﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Web;
using System.Web.Mvc;
using valerij_paschenko_web.Models;

namespace valerij_paschenko_web.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Index(Order ord)
        {

            MailMessage message = new MailMessage();
            message.Subject = "Video Order from vp";
            message.Body = ord.OrderDescription;
            message.From = new MailAddress(ord.FromEmail);
            message.To.Add(new MailAddress("basket.pavlenko@gmail.com"));

            SmtpClient client = new SmtpClient();
            client.Port = 587;
            client.Host = "smtp.gmail.com";
            client.Credentials = new NetworkCredential("basket.pavlenko@gmail.com", "transcend123");
            client.EnableSsl = true;

            client.Send(message);

            client.SendCompleted += client_SendCompleted;

            return View("Default");
        }

        private void client_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            Response.Write("Message sended");
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}